package com.wu.springbootmqproducer.serice.Impl;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.wu.springbootmqproducer.Config.MyConfirmListener;
import com.wu.springbootmqproducer.beans.Goods;
import com.wu.springbootmqproducer.serice.SendService;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.Random;

@Service
public class SendServiceImpl implements SendService {


    @Autowired
    private AmqpTemplate amqpTemplate;


    @Override
    public String send(Goods good) {
        String msg = null;
        try {
            msg = new ObjectMapper().writeValueAsString(good);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
//        amqpTemplate.convertAndSend("queue9",msg);
//        amqpTemplate.convertAndSend("ex1","",msg);
//        amqpTemplate.convertAndSend("ex2","a",msg);

        amqpTemplate.convertAndSend("xj_natural_exchange","xj_natural_routingKey",msg);

        return "sucess";
    }
}
